#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <fcntl.h>
#include <errno.h>
#include "a311d-setenv.h"

/**
 * generate_env - generate environment variable.
 *	@series - series
 *	@model - model
 */
void generate_env(unsigned short series, unsigned short model)
{
	char buff[128] = {0};

	sprintf(buff, "echo \"export SERIES=0x%x\" > /tmp/env-variable.sh", series);
	system(buff);

	memset(buff, 0, 128);
	sprintf(buff, "echo \"export MODEL=0x%x\" >> /tmp/env-variable.sh", model);
	system(buff);

	memset(buff, 0, 128);
	sprintf(buff, "chmod 777 /tmp/env-variable.sh");
	system(buff);

	memset(buff, 0, 128);
	sprintf(buff, "source /tmp/env-variable.sh");
	system(buff);

	// printf("set finish\n");
}

/*
 * abstruct : main program.
 */
int main(int argc, char ** argv)
{
	unsigned char area;
	unsigned short series;
	unsigned short model;
	char sn[13] = {0};

	/* series and model parameter */
	paremeter_operation(sn, &area, &series, &model);

	/* generate environment variable file */
	generate_env(series, model);

	return 0;
}
